package com.aios.action.settings.switchPanel;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.aios.entity.Switch;
import com.aios.entity.SwitchPanel;
import com.aios.service.SwitchPanelService;

public class SwitchPanelListAction extends AbstractSwitchPanelAction {

	private static final long serialVersionUID = 1L;

	private static final int DEFAULT_NUMBER_OF_PANELS = 1;
	private static final int DEFAULT_INDEX = 0;
	
	private List<Switch> switchList;
	private List<SwitchPanel> switchPanelList;
	private String panelId;
	
	@Qualifier("switchPanelService")
	@Autowired protected SwitchPanelService switchPanelService;

	public String execute() {

		switchPanelList = switchPanelService.findByUserId(getSessionUserVariable().getId());
		
		if (switchPanelList == null || switchPanelList.size() < DEFAULT_NUMBER_OF_PANELS) {
			actionError = getText("switch.error.panel.not.exist");
			return INPUT;
		}
		else if(switchPanelList.size() == DEFAULT_NUMBER_OF_PANELS) {
			panelId = switchPanelList.get(DEFAULT_INDEX).getId();
			switchList = switchService.findAllBySwitchPanelId(switchPanelList.get(DEFAULT_INDEX).getId());
		}
		else if(switchPanelList.size() > DEFAULT_NUMBER_OF_PANELS) {
			//use when multiple switch panels available for one user.
		}		
		
		return SUCCESS;
	}

	public List<Switch> getSwitchList() {
		return switchList;
	}

	public void setSwitchList(List<Switch> switchList) {
		this.switchList = switchList;
	}

	public List<SwitchPanel> getSwitchPanelList() {
		return switchPanelList;
	}

	public void setSwitchPanelList(List<SwitchPanel> switchPanelList) {
		this.switchPanelList = switchPanelList;
	}

	public String getPanelId() {
		return panelId;
	}

	public void setPanelId(String panelId) {
		this.panelId = panelId;
	}

}
